package com.gopay.common.cps.dao.gp.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.constants.gp.GpFormalitesTransConstants;
import com.gopay.common.cps.dao.gp.CpsGpContractInfoDAO;
import com.gopay.common.domain.cps.gp.CpsGpContractInfo;
/**
 * P2P签约协议信息
 * @CpsGpContractInfoDAOImpl.java
 * @author lizheng
 * @2014-4-18 下午3:20:12  www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("cpsGpContractInfoDAO")
public class CpsGpContractInfoDAOImpl  extends BaseDAOImpl<CpsGpContractInfo, Serializable> implements CpsGpContractInfoDAO {

    @Override
    public long getNextVal() {
        return Long.parseLong(this.getNextId("CPS_P2P_CONTRACT_INFO_SEQ"));
    }
    @Override
    public CpsGpContractInfo getByContractNo(String contractNo) {
        DetachedCriteria criteria = DetachedCriteria.forClass(CpsGpContractInfo.class);
        criteria.add(Restrictions.eq("contractId", contractNo));
        List<CpsGpContractInfo> list = this.findByCriteria(criteria);
        return list.size() > 0 ? list.get(0) : null;
    }
    @Override
    public boolean isSign(String trustAcct, String excluCustId) {
        // 查询流水
        DetachedCriteria criteria = DetachedCriteria.forClass(CpsGpContractInfo.class);
        criteria.add(Restrictions.eq("trustAcct", trustAcct));
        criteria.add(Restrictions.eq("excluCustId", excluCustId));
        criteria.add(Restrictions.eq("contractStatus", Integer.valueOf(GpFormalitesTransConstants.SIGN_CONTRACT)));

        List<CpsGpContractInfo> orderList = this.findByCriteria(criteria);
        if(null!=orderList&&orderList.size()>0){
            return true;
        }
        return false;
    }
    @Override
    public CpsGpContractInfo getByExcluAcctId(String excluAcctId) {
        // 查询流水
        DetachedCriteria criteria = DetachedCriteria.forClass(CpsGpContractInfo.class);
        criteria.add(Restrictions.eq("excluAcct", excluAcctId));
        criteria.add(Restrictions.eq("contractStatus", Integer.valueOf(GpFormalitesTransConstants.SIGN_CONTRACT)));
        List<CpsGpContractInfo> orderList = this.findByCriteria(criteria);
        return orderList.size() > 0 ?orderList.get(0) :null;
    }
}
